package com.yi.mall.goods.controller;

import com.yi.mall.common.utils.ResponseEnum;
import com.yi.mall.common.utils.Result;
import com.yi.mall.common.model.Brand;
import com.yi.mall.common.model.DTO.BrandDTO;
import com.yi.mall.goods.service.impl.BrandServiceImpl;
import com.yi.mall.goods.service.impl.CategoryBrandServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 品牌表 前端控制器
 * </p>
 *
 * @author zzy
 * @since 2025-07-10
 */
@CrossOrigin(origins = "http://localhost:5500", allowCredentials = "true")
@RestController
@RequestMapping("/goods/brand")
public class BrandController {
    @Autowired
    private CategoryBrandServiceImpl categoryService;

    @Autowired
    private BrandServiceImpl brandService;

    /**
     * 查询所有品牌
     * @return
     */
    @GetMapping("/list")
    public Result list(){
        List<Brand> brands = brandService.list();
        return Result.success(ResponseEnum.SUCCESS,brands);
    }
    /**
     * 按一级分类ID查询
     * @param id
     * @return
     */
    @GetMapping("/category/1/{id}")
    public Result listByOneCategoryId(@PathVariable Integer id){
        List<BrandDTO> brands = categoryService.listByone(id);
        return Result.success(ResponseEnum.SUCCESS,brands);
    }
    /**
     * 按二级分类ID查询
     * @param id
     * @return
     */
    @GetMapping("/category/2/{id}")
    public Result listByTwoCategoryId(@PathVariable Integer id){
        List<BrandDTO> brands = categoryService.listBytwo(id);
        return Result.success(ResponseEnum.SUCCESS,brands);
    }

    /**
     * 按三级分类ID查询
     * @param id
     * @return
     */
    @GetMapping("/category/3/{id}")
    public Result listByThreeCategoryId(@PathVariable Integer id){
        List<BrandDTO> brandDTOS = categoryService.listBythree(id);
        return Result.success(ResponseEnum.SUCCESS,brandDTOS);
    }
}
